rm(list=ls())

##############################################################################
# APPENDIX B1 FIGURE 1
##############################################################################

# load packages
#library(ggplot2)

# load data 
load("data/eurepoc_year_attacks.RData")

avg_attacks1 <- aggregate(attacks ~ candidate + year, data = eurepoc_year_data, FUN = mean, na.rm = TRUE)
avg_attacks1$year <- factor(avg_attacks1$year)
avg_attacks1$candidate <- factor(avg_attacks1$candidate)
avg_attacks1$status <- ifelse(avg_attacks1$candidate == 1, "candidate", "non-candidate")

appendB1_fig1 <- ggplot(avg_attacks1, aes(x= year, y=attacks, group = status, linetype = status)) + theme_bw() +
  geom_line() + theme(panel.grid.major = element_blank(), axis.text.x = element_text(angle = 90, vjust = 0.5)) + labs(y = "Average Number of Incidents", x = "Year") 

# save pdf
ggsave(appendB1_fig1, filename = "output/appendB1_fig1.pdf")

# script complete message 
print("appendB1_fig1 complete")
